(function(_scope) {

var DU_TAG = '0';

if (_scope['__'] == undefined) {
  _scope['__'] = {};
}
var __ = _scope['__'];

if (!__.load) {

  if (__.config == undefined) {
    __.config = {}
  }

  var ua = navigator.userAgent, cua = __.config.ua = {};
  if ((/KHTML/).test(ua)) {
    cua.webkit = true;
  } else if (/Opera/.test(ua)) {
    cua.opera = true;
  } else if (/MSIE/.test(ua)) {
    cua.IE = true;
  } else if (/Gecko/.test(ua)) {
    cua.Gecko = true;
  }

  __.config.loaderBase = [
    '/misc', //production
    'http://double-underscore.googlecode.com/svn' //google code base
    //'http://double-underscore.googlecode.com/svn/yui/2.6.0/build',
    //'http://localhost/stauren.net/develop/3party/yui260/build'
  ];
  __.config.loaderModules = {};

  var _SC = __.config,
  _loadFile = function(type,url,fn) {
    var head = document.getElementsByTagName("head")[0];
   /* if (false && !inHead) {
      //loadFile while page loading
      if(type=="script"){
        document.write('<scr'+'ipt src="'+url+'" type="text/javascript"><\/scr'+'ipt>')
      } else if(type=="css"){
        document.write('<link href="'+url+'" type="text/css" rel="stylesheet"></link>')
      }
    } else {*/
      //loadFile after page is loaded, lots of loading may crash IE
      var node, usera = __.config.ua;
      fn=typeof fn == 'function' ? fn : function(){};
      if(type=="script"){
        node = document.createElement('script');
        node.type = 'text/javascript';
        node.src = url;
        node.charset = 'utf-8';
      } else if(type=="css") {
        node = document.createElement('link');
        node.type = 'text/css';
        node.rel = 'stylesheet';
        node.href = url;
        node.charset = 'utf-8';
      }
      if (usera.IE) {
        node.onreadystatechange = function() {
          var rs = this.readyState;
          if ("loaded" === rs || "complete" === rs) {
            fn();
          }
        };
      } else if (usera.webkit) {
        if (type === "script") {
          node.addEventListener("load", function() {
            fn();
          });
        } 
      } else {
        node.onload = function() {
          fn();
        }
      }
      head.appendChild(node);
   // }
  }, _loadModuleByName = function(modName,getObj) {
    var loadingItem = _SC.loaderModules[":"+modName];
   /* if (getObj && getObj.dynamic) {
      inHead = !!getObj.dynamic;
    }*/
    if(!loadingItem){
      _loadFile('script', modName, getObj && getObj.onSuccess)
    } else {
      var type = (loadingItem.detailObj && loadingItem.detailObj.type) || 'script';
      _loadFile(type,loadingItem.get(getObj), getObj && getObj.onSuccess)
    }
  }, 
  /**
   * @param {string|array} n an url of js file or module names to load, array of module names will be load simultaneously, space seperated string of module names will be load in tandem, 
   * @param {object} getObj configuration
   * @config {string} version version, 0 mean trunk
   * @config {string} type css or js
   */
  _load = function(n,getObj) {
    if (Object.prototype.toString.apply(n) === '[object Array]') {
      for (var i=0,j=n.length;i<j;i++) {
        _load(n[i], getObj);
      }
    } else {
      n = n.split(' ');
      var newObj, firstN = n.shift();
      if (n.length >= 1)  {
        newObj = {};
        for (var at in getObj) {
          newObj[at] = getObj[at];
        }
        newObj['onSuccess'] = function() { _load(n.join(' '), getObj) };
      } else {
        newObj = getObj;
      }

      _loadModuleByName(firstN, newObj);
    }
  }, _LoadModule = function (modName, detailObj) {
    this.mname = modName;
    this.detailObj = detailObj || {};
  }; 
  _LoadModule.prototype.get = function(getObj) {
    getObj = getObj || {};

    //default : local file
    var isDebug = _SC.debug === true ? true : false,
      type = this.detailObj['type'] || 'js',
      source = this.detailObj['source'] || 'DU',
      sBase, name = this.mname;

    switch (source) {
      case 'DU' :
        //product on double-undersocre, debug on local
        if (isDebug) {
          sBase = [_SC.loaderBase[0], type].join('/');
          name += '_comment';
        } else {
          sBase = _SC.loaderBase[1];
          var edition = _SC.DU_TAG ? _SC.DU_TAG :
            (getObj.version ? getObj.version : DU_TAG);
          if (edition == '0') { // load trunk
            sBase += '/trunk/src';
          } else { // load special tags
            sBase += '/tags/' + edition;
            //sBase = [_SC.loaderBase[1], edition].join('/');
          }
        }
        break;
        /*
      case 'YUI' :
        //product on double-undersocre, debug on local
        if (isDebug) {
          sBase = [_SC.loaderBase[3], this.detailObj['module'] ? this.detailObj['module'] : name].join('/');
          name += this.detailObj['beta'] ? '-beta' : '';
        } else {
          sBase = [_SC.loaderBase[2], name].join('/');
          name += (this.detailObj['beta'] ? '-beta' : '') + '-min';
        }
        break;
        */
      case 'ST' :
        //product on stauren.net, debug on local
          sBase = [_SC.loaderBase[0], type].join('/');
        if (isDebug) {
          name += '_comment';
        }
        break;
    }

    name += type == 'css' ? '.css' : '.js';
    if (isDebug) {
      name += '?_t='+Math.random();
    }
    return [sBase, name].join('/')
  };


    var loadingList = _SC.loaderModules;
    loadingList[":bcss"]=new _LoadModule("base", {type:'css', source:'ST'});
    loadingList[":stcss"]=new _LoadModule("stauren", {type:'css', source:'ST'});
    loadingList[":b-stcss"]=new _LoadModule("base-stauren", {type:'css', source:'ST'});

    loadingList[":yeditorcss"]=new _LoadModule("yeditor", {type:'css', source:'ST'});
    loadingList[":yeditor"]=new _LoadModule("yeditor",{source:'ST'});
    loadingList[":yelement"]=new _LoadModule("yelement", {source:'ST'});

    loadingList[":stauren"]=new _LoadModule("du_core", {source:'ST'});
    loadingList[":validator"]=new _LoadModule("validator", {source:'ST'});
    loadingList[":ydecja"]=new _LoadModule("ydecja", {source:'ST'});

    loadingList[":du"]=new _LoadModule("du_4load", {source:'DU'});
    loadingList[":stbase"]=new _LoadModule("staurennet", {source:'DU'});
    loadingList[":es"]=new _LoadModule("es", {source:'DU'});
    loadingList[":imagecropper"]=new _LoadModule("image_cropper", {source:'DU'});
    //loadingList[":yui252"]=new _LoadModule("yui252", {source:'DU'});

    __.load = _load;
}
})(window);
